const mysql = require('mysql2/promise');

// 数据库配置
const dbConfig = {
    host: '43.143.253.188',
    port: 3306,
    user: 'nextjs',
    password: 'yEAiRE2jcxTyRBy5',
    database: 'nextjs',
    charset: 'utf8mb4'
};

async function checkTableStructure() {
    let connection;

    try {
        console.log('🔍 检查表结构...');

        // 连接数据库
        connection = await mysql.createConnection(dbConfig);
        console.log('✅ 数据库连接成功');

        // 检查characters表结构
        console.log('\n📋 characters表结构:');
        const [charactersColumns] = await connection.execute('DESCRIBE characters');
        charactersColumns.forEach(col => {
            console.log(`  ${col.Field}: ${col.Type} ${col.Null === 'NO' ? 'NOT NULL' : 'NULL'} ${col.Key ? col.Key : ''}`);
        });

        // 检查gem_base表结构
        console.log('\n📋 gem_base表结构:');
        const [gemBaseColumns] = await connection.execute('DESCRIBE gem_base');
        gemBaseColumns.forEach(col => {
            console.log(`  ${col.Field}: ${col.Type} ${col.Null === 'NO' ? 'NOT NULL' : 'NULL'} ${col.Key ? col.Key : ''}`);
        });

    } catch (error) {
        console.error('❌ 检查失败:', error);
        throw error;
    } finally {
        if (connection) {
            await connection.end();
            console.log('🔌 数据库连接已关闭');
        }
    }
}

// 运行检查
checkTableStructure().catch(console.error);
